require 'iconv'
module WWW
  class Tkd
    class TbOrder < ActiveRecord::Base
     #根据最后修改时间对Seller Order进行排序并搜索
      def self.find_seller_on_page(domain_login_id,page_num, page_size)

        find(:all,

        :conditions => "seller_nick ='#{domain_login_id}'",

        :order => "order_created_at desc",

        :limit => page_size,

        :offset => page_num)

      end
      #获得用户在途的订单
      def self.find_seller_doing_express(domain_login_id)
        find(:all,
        :conditions => "seller_nick='#{domain_login_id}'  and id in(select t1.order_id from tb_seller_orders t1,expresses t2  where t1.express_id is not null and t1.express_id=t2.id and t2.is_end=0)",
        :order => "order_created_at desc"
       )
      end
     #计算总数
      def self.count_seller(domain_login_id)
        return self.count_by_sql(["select count(id) from tb_orders where seller_nick = ?", domain_login_id])
      end
      #根据最后修改时间对Seller Order进行排序并搜索
      def self.find_buyer_on_page(domain_login_id,page_num, page_size)

        find(:all,

        :conditions => "buyer_nick ='#{domain_login_id}'",

        :order => "order_created_at desc",

        :limit => page_size,

        :offset => page_num)

      end
     #计算总数
      def self.count_buyer(domain_login_id)
        return self.count_by_sql(["select count(id) from tb_orders where buyer_nick = ?", domain_login_id])
      end
    end
  end
end
